<?php
class School extends AppModel{
	var $name = "School";
	var $validate = array(
                'name'=>array(
                    'rule' => 'isUnique',
                    'message' => ''),
	);
	
	var $hasMany = array(
		'Campus' => array(
			'className' => 'Campus',
			'foreignKey' => 'school_id'
		)
	);

	function search($words, $offset = 0, $count = 10){
		$likes = array();
		foreach ($words as $key => $word) {
			$likes['or'][]['School.name LIKE'] = "%{$word}%";
			$likes['or'][]['School.kana LIKE'] = "%{$word}%";
		}
		return $this->find('all',array('conditions' => array($likes), 'limit' => $count, 'offset' => $offset));
	}
	
	function findByCampusId($campusId){
		$options = array(
				'conditions' => array(
					'Campus.id' => $campusId
				)
		);
		return $this->find('all',$options);
	}
}
?>